package com.hmall.item.service.impl;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.hmall.common.dto.PageDTO;
import com.hmall.item.mapper.ItemMapper;
import com.hmall.item.pojo.Item;
import com.hmall.item.service.IItemService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;



import java.util.List;

@Service
public class ItemService extends ServiceImpl<ItemMapper, Item> implements IItemService {

    @Autowired
    private ItemMapper itemMapper;

    @Autowired
    private IItemService service;

    @Override
    public PageDTO<Item> list(Integer page, Integer size) {
        Page<Item> itemPage = new Page<>(page,size);

        LambdaQueryWrapper<Item> lqw = new LambdaQueryWrapper();
        lqw.orderByDesc(Item::getUpdateTime);
        Page<Item> page1 = service.page(itemPage, lqw);
        long total = page1.getTotal();
        List<Item> items = page1.getRecords();
        PageDTO<Item> pageDTO = new PageDTO<>();
        pageDTO.setList(items);
        pageDTO.setTotal(total);
        return pageDTO;
    }

}
